fix(composer): preserve quote focus on iOS devices#532
fix(composer): preserve quote focus on iOS devices#532vforsh wants to merge 2 commits intoDimillian:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca24fc76f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| onMouseDown={() => { | ||
| selectionSnapshotRef.current = getSelectedMessageText(); | ||
| }} | ||
| onTouchStart={() => { | ||
| selectionSnapshotRef.current = getSelectedMessageText(); |
There was a problem hiding this comment.
Avoid overwriting touch selection snapshot on mousedown
On touch browsers that emit compatibility mouse events (notably iOS Safari and many Android WebViews), onTouchStart can capture the highlighted fragment, but the later synthetic onMouseDown on the same button may run after the selection has collapsed and overwrite selectionSnapshotRef with null; handleQuote then quotes the full message instead of the selected fragment. This makes touch-based fragment quoting unreliable specifically in those environments.
Useful? React with 👍 / 👎.
Summary
requestAnimationFramefocus pass to re-apply caret position after state updateProblem
On real iOS devices, tapping Quote message inserted text but often did not move focus/caret into the composer. The simulator allowed it, but physical Safari/WebKit can reject delayed focus that is no longer tied to the original user gesture.
Fix
focus()+setSelectionRange()synchronously insideuseComposerInsertbefore state updaterequestAnimationFrameto preserve final cursor placement after renderValidation
npm run test -- src/features/app/hooks/useComposerInsert.test.tsxnpm run typecheck